package com.jonniespratley.generators
{
	import com.adobe.utils.StringUtil;
	
	public class MySQLGen implements IMySQL
	{
		public function MySQLGen()
		{
		}

		public function alterDatabase( database:String=null, charset:String=null, collation:String=null ):String
		{
			return null;
		}
		
		public function alterTable(database:String, table:String, specification:Array=null):String
		{
			return null;
		}
		
		public function createDatabase(database:String, charset:String=null, collation:String=null):String
		{
			return null;
		}
		
		public function createIndex(database:String, table:String, column:String, length:int=11):String
		{
			return null;
		}
		
		public function createTable( database:String, table:String, columns:Array ):String
		{
			
			return null;
		}
		
		public function dropDatabase(database:String, ifExists:Boolean=true):String
		{
			return null;
		}
		
		public function dropIndex(database:String, table:String, index:String):String
		{
			return null;
		}
		
		public function dropTable(database:String, table:String, ifExists:Boolean=true):String
		{
			return null;
		}
		
		public function renameTable(database:String, oldTable:String, newTable:String):String
		{
			return null;
		}
		
		public function deleteStatement( database:String, table:String, columnValuePair:Array ):String
		{
			var uglySql:String = 'DELETE FROM ' + database + '.' + table + ' WHERE ';
			
			for ( var element:String in columnValuePair )
			{
				uglySql += element + " = " + this._prepareString( columnValuePair[ element ] ) + ", ";
			}
			
			return _cleanQuery( uglySql );
		}
		
		public function loadDataStatement(database:String, table:String, filename:String):String
		{
			return null;
		}
		
		public function insertStatement( database:String, table:String, columnValuePair:Array ):String
		{
			var uglySql:String = 'INSERT INTO ' + database + '.' + table + ' SET ';
			
			//loop the objects in the array
			for ( var i:int = 0; i < columnValuePair.length; i++ ) 	
			{ 
				//get each object
				var obj:Object = new Object();
					obj = columnValuePair[ i ];
				
				//pull out the key = value from every object
				for ( var s:String in obj )
				{
					trace( 'Column: ' + s + ' Value: ' + obj[ s ] );
					
					uglySql += s + ' = ' + _prepareString( obj[ s ] ) + ',';	
				}
			}
			return _cleanQuery( uglySql );
		}
		
		public function updateStatement( database:String, table:String, columnValuePair:Array ):String
		{
			var uglySql:String = 'UPDATE ' + database + '.' + table + ' SET ';
			
			for ( var element:String in columnValuePair )
			{
				uglySql += element + " = " + this._prepareString( columnValuePair[ element ] ) + ", ";
			}
			
			return _cleanQuery( uglySql );
		}
		
		public function selectStatement( database:String, table:String, selectExpr:String = null, conditionExpr:Array = null ):String
		{
			var uglySql:String = 'SELECT ';
			
			if ( selectExpr != null )
			{
				for ( var s:String in selectExpr )
				{
					uglySql += s + ", ";
				}
			}
			
			uglySql += 'FROM ' + database + '.' + table;
			
			if ( conditionExpr != null )
			{
				uglySql += ' WHERE ';
				for ( var t:String in conditionExpr )
				{
					uglySql += t + " = " + this._prepareString( selectExpr[ s ] ) + ", ";
				}
			}	
			return _cleanQuery( uglySql );
		}
		
		public function selectJoinStatement(database:String, table:String, fromTable:String, columnValuePair:Array=null):String
		{
			return null;
		}
		
		public function selectUnionStatement(database:String, table:String, fromTable:String, columnValuePair:Array=null):String
		{
			return null;
		}
		
		public function getClients():String
		{
			return null;
		}
		
		public function getCommands():String
		{
			return null;
		}
		
		public function getConnections():String
		{
			return null;
		}
		
		public function getInnoDB():String
		{
			return null;
		}
		
		public function getKeys():String
		{
			return null;
		}
		
		public function getOpen():String
		{
			return null;
		}
		
		public function getPerformance():String
		{
			return null;
		}
		
		public function getQueryCache():String
		{
			return null;
		}
		
		public function getQuestions():String
		{
			return null;
		}
		
		public function getReplication():String
		{
			return null;
		}
		
		public function getServerInfo():String
		{
			return null;
		}
		
		public function getShowCommands():String
		{
			return null;
		}
		
		public function getSort():String
		{
			return null;
		}
		
		public function getTemp():String
		{
			return null;
		}
		
		public function getThreads():String
		{
			return null;
		}
		
		public function getSystemStatus():String
		{
			return null;
		}
		
		public function getSystemVariables():String
		{
			return null;
		}
		
		public function getSystemUsers():String
		{
			return null;
		}
		
		public function getSystemProcesses():String
		{
			return null;
		}
		
		public function getSystemPrivileges():String
		{
			return null;
		}
		
		public function showCharacterSet():String
		{
			return null;
		}
		
		public function showCollation():String
		{
			return null;
		}
		
		public function showCreateDatabase(database:String):String
		{
			return null;
		}
		
		public function showCreateProcedure():String
		{
			return null;
		}
		
		public function showCreateFunction():String
		{
			return null;
		}
		
		public function showCreateTable(database:String, table:String):String
		{
			return null;
		}
		
		public function showCreateView():String
		{
			return null;
		}
		
		public function showDatabases():String
		{
			return null;
		}
		
		public function showEngine():String
		{
			return null;
		}
		
		public function showEngines():String
		{
			return null;
		}
		
		public function showErrors():String
		{
			return null;
		}
		
		public function showGrants():String
		{
			return null;
		}
		
		public function showIndex(database:String, table:String):String
		{
			return null;
		}
		
		public function showOpenTables(database:String):String
		{
			return null;
		}
		
		public function showStatus(database:String):String
		{
			return null;
		}
		
		public function showTableStatus(database:String):String
		{
			return null;
		}
		
		public function showProcesslist():String
		{
			return null;
		}
		
		public function showWarnings():String
		{
			return null;
		}
		
		public function showTriggers():String
		{
			return null;
		}
		
		public function showTables(database:String):String
		{
			return null;
		}
		
		private function _prepareString( str:String ):String
		{
			var s:String = "'" + str + "'";
			
			return s;
		}
		
		private function _cleanQuery( uglyQuery:String ):String
		{
			//we need to strip the last comma for now
			var pattern:RegExp = /\W$/g;
			
			var cleanSql:String = uglyQuery.replace( pattern, '' );
			
			return cleanSql;
		} 
		
	}
}